<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use Hyperf\HttpServer\Annotation\Controller;
use Mine\Mine;
use Mine\MineController;
use Mine\MineRequest;
use Mine\MineResponse;

#[Controller('ch/oauth')]
class OauthController extends MineController
{

    protected string $redirect_uri;

    protected string $oauthCallbackUrl = 'https://router.wikeyun.cn/api/Oauth/redirect';

    public function __construct(Mine $mine, MineRequest $request, MineResponse $response)
    {
        parent::__construct($mine, $request, $response);

        $this->redirect_uri = $this->request->input('redirect_uri');
    }

    public function taobao(){
        $query = [
            'serviceType'  => $this->request->all()['serviceType'],
            'redirect_uri' => $this->redirect_uri
        ];
        $redirect_uri = urlencode($this->oauthCallbackUrl.'?'.http_build_query($query));
        $urls = "https://oauth.taobao.com/authorize?response_type=code&client_id={$this->appkey}&redirect_uri={$redirect_uri}";
        header("Location:".$urls);
    }
}